﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
using Tong.ThisSiteUse;
public partial class aspnet_admin_bock_Create_Create_HTML_Column : System.Web.UI.Page
{

    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;

    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable ShowTreeMyDt = new DataTable();

    DataTable Create_HTML_ColumnNewDt = new DataTable();
    CreateSiteHTMlFile CHmlt = new CreateSiteHTMlFile();


    public string SumID;

    public string TimeID;
    protected void Page_Load(object sender, EventArgs e)
    {

        SumID = filesum.ClientID;

        TimeID = temesx.ClientID;
        //生成最新
        Button2.Attributes.Add("onclick", "sendNue('NewsX',document.getElementById('" + TextBox1.ClientID + "').value)");

        Button3.Attributes.Add("onclick", "sendNue('All','0')");
        Button5.Attributes.Add("onclick", "sendNue('All','0')");
        Button4.Attributes.Add("onclick", "sendNue('one',document.getElementById('"+ListBox1.ClientID+"').value)");

        if (!IsPostBack)
        {
            Create_HTML_ColumnNewDt.Columns.Add("东东");
            Create_HTML_ColumnNewDt.Columns.Add("Conts");
            ShowTree(0);
            
            ListBox1.DataSource = Create_HTML_ColumnNewDt.DefaultView;
            ListBox1.DataTextField = "Conts";
            ListBox1.DataValueField = "东东";
            ListBox1.DataBind();
            Create_HTML_ColumnNewDt.Clear();
            Create_HTML_ColumnNewDt.Dispose();
            System.GC.Collect();//回收LJ
        }
        
    }

    /// <summary>
    /// 按栏目生成操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button4_Click(object sender, EventArgs e)
    {
        string  CX_Column = ListBox1.SelectedValue.Trim();
        if (CX_Column != "")
        {
            string strX = CHmlt.Creat_Column(CX_Column);
            if (strX == "")
            {
                tt.Text = " 生成栏目成功 ";
            }
            else
            { 
                tt.Text = strX;
            }
            
        }
        else
        {
            tt.Text = "请选择要生成栏目";
        }
        System.GC.Collect();//回收LJ
    }

    //生成新闻
    protected void CreaeNews(object sender, EventArgs e)
    {
        try
        {
            
            string strX = CHmlt.Creat_New_News(int.Parse(TextBox1.Text.Trim()));

            if (strX == "")
            {
                tt.Text = " 生成新闻成功 ";
            }
            else
            {
                tt.Text = strX;
            }

        }
        catch(Exception ex)
        {
            tt.Text = "请输入数字";
        }
        System.GC.Collect();//回收LJ
    }

    
    /// <summary>
    /// 反向生成全部栏目
    /// </summary>
    protected void CreateAllRe(object sender, EventArgs e)
    {
        DataTable CreateAllMyDt = new DataTable();
        DataSet CreateAllMyDs = new DataSet();

        CreateAllMyDs = TextData.SqlataSet("select * from [CX_Column] where  CX_Column_LX<>3  order by [CX_Column_id] desc");//生成不为系统栏目的东东

   //     try
    //    {
            CreateAllMyDt = CreateAllMyDs.Tables[0];
            for (int i = 0; i < CreateAllMyDt.Rows.Count; i++)
            {
                string strX = CHmlt.Creat_Column(CreateAllMyDt.Rows[i]["CX_Column_id"].ToString());
                //System.Threading.Thread.Sleep(100);
                if (strX == "")
                {
                    tt.Text = " 生成成功 ";
                }
                else
                {
                    tt.Text = strX;
                }



            }
//        }
 //       catch (Exception ex)
 //       {
 //           TextData.Err(ex.Message+ex.InnerException+"出错了");
//        }
        
       // MyDt.Clear();
        CreateAllMyDs.Clear();
        CreateAllMyDs.Dispose();
        CreateAllMyDt.Dispose();
       System.GC.Collect();//回收LJ




    }

    /// <summary>
    /// 生成全部栏目
    /// </summary>
    protected void CreateAll(object sender, EventArgs e)
    {
        DataTable CreateAllMyDt = new DataTable();
        DataSet CreateAllMyDs = new DataSet();

        CreateAllMyDs = TextData.SqlataSet("select * from [CX_Column] where CX_Column_LX<>3 ");//生成不为系统栏目的东东

   //     try
    //    {
            CreateAllMyDt = CreateAllMyDs.Tables[0];
            for (int i = 0; i < CreateAllMyDt.Rows.Count; i++)
            {
                string strX = CHmlt.Creat_Column(CreateAllMyDt.Rows[i]["CX_Column_id"].ToString());
                //System.Threading.Thread.Sleep(100);
                if (strX == "")
                {
                    tt.Text = " 生成成功 ";
                }
                else
                {
                    tt.Text = strX;
                }



            }
//        }
 //       catch (Exception ex)
 //       {
 //           TextData.Err(ex.Message+ex.InnerException+"出错了");
//        }
        
       // MyDt.Clear();
        CreateAllMyDs.Clear();
        CreateAllMyDs.Dispose();
        CreateAllMyDt.Dispose();
       System.GC.Collect();//回收LJ




    }


    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable ShowTreeMyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            ShowTreeMyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < ShowTreeMyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = Create_HTML_ColumnNewDt.NewRow();
                Row[0] = ShowTreeMyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + ShowTreeMyDt.Rows[i]["CX_Column_Name"].ToString();
                Create_HTML_ColumnNewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = Create_HTML_ColumnNewDt.NewRow();
                Row[0] = ShowTreeMyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + ShowTreeMyDt.Rows[i]["CX_Column_Name"].ToString();
                Create_HTML_ColumnNewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(ShowTreeMyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }


    //生成首页
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
              TextData.GetWebDataWrite(TongUse.SysPath+"aspnet/testPargrameDir/site/Default.aspx",Server.MapPath("/html/index.html"));
              TextData.GetWebDataWrite(TongUse.SysPath + "aspnet/testPargrameDir/site/Default.aspx", Server.MapPath("/index.html"));
              tt.Text = "生成首页成功";
        }
        catch
        { 
                System.GC.Collect();//回收LJ
        }
    }
}

